<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<title>工序报工</title>
		<link rel="stylesheet" type="text/css" href="../css/api.css"/>
		<link rel="stylesheet" type="text/css" href="../css/aui.css" />
		<link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
		<link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
		<link rel="stylesheet" type="text/css" href="../css/aui-list-swipe.css" />
		<link rel="stylesheet" type="text/css" href="../css/isDialog.css" />
		<link rel="stylesheet" type="text/css" href="../../layui/css/layui.css" media="all" />

		<style type="text/css">
			body {
				font-family: Arial;
				background-color: #ffffff;
			}
			/* 输入框下面的列表标题行（未完成的检测单信息）样式 */
			p.cimc-grid-label {
				border-left: 0.25 rem solid rgba(22, 155, 213, 1);
				padding-left: 0.3 rem;
			}
			span.cimc-grid-label {
				color: #000;
				font-size: 16px;
			}
			ul.aui-list:before {
				height: 0px !important;
			}/**** 去掉条目的细线 ****/
			div.cimc-list-header {
				height: 1.8 rem !important;
				min-height: 0px !important;
			}
			/**** 每条条目的高度 ****/
			li.aui-list-item {
				min-height: 0px !important;
			}/* 去掉最小高度限制 */
			div.cimc-list-item-inner {
				min-height: 0px !important;/* 去掉最小高度限制 */
				padding-top: 0.2 rem;
				padding-right: 0.1 rem !important;
				height: 32px;
			}
			/* 去掉每一行自带的间隔线 */
			div.cimc-list-item-inner:after {
				height: 0px !important;
				background-color: #000000 !important;
			}
			/* 设置标签体字体大小 */
			div.cimc-list-item-inner-lable {
				text-align: left;
				padding-top: 0rem !important;
				padding-bottom: 0rem !important;
				text-align: left;
				font-size: 13px;
				/*width:50%;*/
			}
			.table {
				margin-bottom: 15px;
				width: 100%;
				border-collapse: collapse;
				font-size: 13px;
				height:25px;
			}
			.table td {
				height: 25px;
				text-align: center;
				border: 1px solid #CBD6DE;
				font-size: 14px;
				padding: 0;
				margin: 0;
				vertical-align: middle !important;
			}

			#tr2 td {
				font-size: 13px
			}

			.weui-form-preview {
				position: static;
				margin-bottom: 56rpx;
				background-color: transparent;
				padding-top: 10rpx;
			}
			.weui-form-preview:before {
				border-top: none;
				border-bottom: none;
			}
			.weui-form-preview:after {
				border-top: none;
				border-bottom: none;
			}
			.weui-form-preview__hd {
				position: static;
			}
			.font-color {
				color: #6b717d;
			}
			.view-title {
				float: left;
				text-align: justify;
				text-align-last: justify;
				font-weight: bold;
			}
			.view-title-height {
				line-height: 16px;
				font-weight: normal;
				font-size: 15px;
			}
			.view-content-height {
				line-height: 15px;
				font-weight: normal;
				padding-top: 5px;
			}
			.view-bottom {
				padding-bottom: 10rpx;
			}
			.view-left {
				float: left;
				font-weight: normal;
			}
			.view-justify {
				text-align: justify;
				text-align-last: justify;
			}
			.normal {
				font-weight: normal
			}
			.weui-form-preview__hd:after {
				content: " ";
				position: absolute;
				left: 0;
				bottom: 0;
				right: 0;
				height: 1px;
				border-bottom: none;
				left: 15px;
				right: 15px;
			}
			.weui-form-preview__hd::before {
				border-bottom: none;
			}
			.card {
				border: 2px solid #ffffff;
				border-radius: 6px;
				background-color: #ffffff;
				margin: 6px;
				margin-top: -5px;
			}
			.inline {
				display: inline
			}
			.title_bold {
				font-weight: bold
			}
			.title_normal {
				font-weight: normal
			}
			.weui-form-preview__item {
				overflow: hidden
			}
			.btn_color {
				background-image: radial-gradient(circle 248px at center, #16d9e3 0%, #30c7ec 47%, #46aef7 100%);
				color:white;
			}
			.btn_color-start {
				background-image: linear-gradient(to right, #E3E0E0 , #F2F2F2);
			    color: black;
			}

			.btn_color-after {
				background-image: linear-gradient(to right, #A3A3A3 , #A1A1A1);
			    color: black;
			}

			.btn_radius {
			    border-radius: 15px;
			}

			.show {
				display:flex;
			}

			.hide {
				display:flex;
				display:none;
			}

			.state {
				overFlow-x: scroll;
				overFlow-y: hidden;
				white-space: nowrap;
			}
			.state::-webkit-scrollbar {
                display: none;
            }

			.aui-btn-block {
			    display: block;
			    width: 100%;
			    padding: 5px 0;
			    margin-bottom: 0;
			    font-size: 0.9rem;
			}

			.form-group {
			    display: inline-block;
			}

			.form-label {
				float: left;
				width:80px;
				height:35px;
				line-height: 35px;
				text-align: right;
			}

             .form-label_peed {
				text-align:center;
				margin:0 auto;
				height:35px;
				line-height: 35px;
				font-size:18px;
		      }
			.form-control {
				margin-left:15px;
			    /*display: block;*/
			    width: 120px;
			    height: 35px;
			    padding: 6px 12px;
			    font-size: 2.73333vw;
			    line-height: 1.5;
			    color: #495057;
			    background-color: #fff;
			    background-clip: padding-box;
			    border: 1px solid #ced4da;
			    border-radius: 4px;
			    transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
			}

			.effQty_after {
				margin-left:0;
			}

			.effQty_before {
				margin-left:30px;
			}

			.mandatory{
            	color: red;
            	float: left;
				height: 35px;
				width: 5px;
				line-height: 35px;
				margin: 0 5px;
        	}

        	.margin-left20 {
        		margin-left:20px
        	}

        	.notclick {
        	    pointer-events:none;
        	}

        	.editok {
        		background: gainsboro;
        		border-radius: 4px;
        	}
			.layui-progress{position:relative;height:6px;border-radius:20px;background-color:#e2e2e2}
			.layui-progress-bar{position:absolute;left:0;top:0;width:0;max-width:90px;height:6px;border-radius:20px;text-align:right;background-color:#5FB878;transition:all .3s;-webkit-transition:all .3s}
			.layui-progress-big,.layui-progress-big .layui-progress-bar{height:18px;line-height:18px}
			.layui-progress-text{position:relative;top:-20px;line-height:18px;font-size:12px;color:#666}
			.layui-progress-big .layui-progress-text{position:static;padding:0 10px;color:#fff}
			.layui-bg-green,.layui-bg-orange,.layui-bg-red{color:green}
		</style>
	</head>
	<body>
		<header id='header' class="aui-bar aui-bar-nav" style="background-color: #03a9f4">
		    <a class="aui-pull-left aui-btn" onclick="closeWin();">
		        <span class="aui-iconfont aui-icon-left"></span>
		    </a>
		    <div class="aui-title" id="middle">
		    	工序报工
		    </div>
		    <a class="aui-pull-right aui-btn" onclick="getTabList()">
			        <span style="padding-right:5px;"class="aui-iconfont aui-icon-recovery"></span>
			</a>
		</header>
		<div class="aui-content-padded" style="display:flex;margin: 0.4rem;">
			<p>
				<div id="operate" class="aui-btn aui-btn-block btn_radius" >
					操作
				</div>
			</p>

			<p style="width:50px"></p>
			<p>
				<div id="full" class="aui-btn aui-btn-block btn_radius" onclick="goReportWork()">
					工序报工
				</div>
			</p>
		</div>
		<div class='aui-list-item-inner cimc-list-item-inner' style='height:90px;border: 1px solid #cdc1c1;padding-left: 10px;background-color: #f5f5f5;'>
			<div id="workOrderCode" class='aui-grid-label cimc-list-item-inner-lable' style='display:inline;font-size:15px;width: 52.5%;float: left;'>
				工单:
			</div>
			<div></div>
			<!-- <div id="lastEffectiveQty" class='aui-grid-label cimc-list-item-inner-lable state' style='display:inline;font-size:15px;width: 47.5%;float: left;'>
				前良品数:
			</div> -->
			<!-- <div id="workCellName" class='aui-grid-label cimc-list-item-inner-lable state' style = 'display:inline;font-size:15px;width: 52.5%;float: left;'>
				工位:
			</div> -->
			<!-- <div></div> -->

			<div id="mrl" class='aui-grid-label cimc-list-item-inner-lable state' style = 'display:inline;font-size:15px;width: 82.5%;float: left;'>
			            产品:
			</div>
			<div></div>
			<div id="planQty" class='aui-grid-label cimc-list-item-inner-lable' style = 'display:inline;font-size:15px;width: 82.5%;float: left;'>
				计划:
			</div>
			<div></div>
			<div id="effectiveQty" class='aui-grid-label cimc-list-item-inner-lable' style = 'display:inline;font-size:15px;width: 33%;float: left;'>
				良品:
			</div>
			<div id="uneffectiveQty" class='aui-grid-label cimc-list-item-inner-lable' style = 'display:inline;font-size:15px;width: 33%;float: left;'>
				不良品:
			</div>
			<div id="discardQty" class='aui-grid-label cimc-list-item-inner-lable' style = 'display:inline;font-size:15px;width: 33%;float: left;'>
				报废:
			</div>
			<div></div>
		</div>
		<div id="searchDiv2" class="aui-form">
			<ul class="aui-list aui-form-list" style="font-size: 14px;">
				<li class="aui-list-item">
					<div class="aui-list-item-inner" style="width:100%">
						<div class="aui-list-item-label1" style="margin-top:5px;font-size: 14px;">
							<img src="../image/scanner.png" />
						</div>
						<input class="aui-input" placeholder=" 请扫描箱号 "
						style="width: 80%;font-size: 18px;" id="huCode2" onkeydown="onkeydownHuCode2()"/>
						<i class="aui-input-addon aui-iconfont aui-icon-scan " style="padding-right:10px;font-size: 1.6rem" onclick="toScanner('huCode2');"></i>
					</div>
				</li>
			</ul>
		</div>
		<div class="table-responsive" id="appStorage" style="overflow-y:auto">
			<table id="tab" class="table table-bordered " style="margin-top:10px;">
				<thead style="width: calc( 100% - 1em)">
					<tr id="tr2" style="display: table;width: 100%;table-layout: fixed;text-align: center;background-color: #DCE9F2;color: #467aa7;font-family: 微软雅黑;font-size: 13px;font-weight: bold;">
						<td style="width:30px">序号</td>
						<td style="width:70px">操作类型</td>
						<td style="width:50px">良品</td>
						<td style="width:50px">不良</td>
						<td style="width:50px">报废</td>
					</tr>
				</thead>
				<tbody id="J_TbData" style=" display: block;height: 200px;overflow-y: scroll;">

				</tbody>
			</table>
		</div>

		<div id="operate_ref" class="aui-content-padded show">
			<p>
				<div id="start_btn" class="aui-btn aui-btn-block btn_color" onclick="setState('0')">
					开工
				</div>
			</p>
			<p style="width:50px"></p>
			<p>
				<div id="pause_btn" class="aui-btn aui-btn-block btn_color"  onclick="setState('1')">
					暂停
				</div>
			</p>
			<p style="width:50px"></p>
			<p>
				<div id="back_btn" class="aui-btn aui-btn-block btn_color"  onclick="setState('2')">
					复工
				</div>
			</p>
			<p style="width:50px"></p>
			<p>
				<div id="finish_btn" class="aui-btn aui-btn-block btn_color"  onclick="setState('4')">
					完工
				</div>
			</p>
		</div>
	</body>
	<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../script/isDialog.js"></script>
	<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript" src="../script/doT.min.js"></script>
	<script type="text/javssssascript" src="../script/zepto.min.js"></script>
	<script type="text/javascript" src="../script/aui-list-swipe.js"></script>
	<script type="text/javascript" src="../script/public.js"></script>
	<script src="../script/swiper.min.js"></script>
	<script type="text/javascript">
	 	var trackId; // 派工任务主键
		var op; // 工序
		var workCellCode; // 工位编码
		var mrl; // 产品
		var disCodeState; // 派工任务状态
		var pauseReason; // 暂停原因

		var isAutoPLC; // PLC自动报工
		var isUseHu; // 消耗HU
		var isNonFull; // 非满托
		var isChoosePackage; // 选择包装&隔离
		var isMantissa; // 需要提醒尾数

		var isCreateFirstChk = false; // 是否创建首件检验
		var noFullDragReason;  // 非满拖原因
		var noFullDragQty; // 非满拖数量
		var trackRecordList = null; // 执行工单集合
		var lastWorkCell; // 最后一次操作工位
		var track; // 派工数据
		var startStyleStr = "aui-btn aui-btn-block btn_radius btn_color-start";
	    var afterStyleStr = "aui-btn aui-btn-block btn_radius btn_color-after";
	    var showStyleStr = "aui-content-padded show";
	    var hideStyleStr = "aui-content-padded hide";
	    var startBtn = "aui-btn aui-btn-block btn_color";
	    var afterBtn = "aui-btn aui-btn-block btn_color-after notclick";
	    var reportWorkCellCode;
	    var isPack;
	    var lotCode;
	    var operateIndex; // 当前操作索引
		var code = '';
		var isNoFullUseHu; // 是否非满箱扣料 0否1是
		apiready = function() {
			$('#workCellCode').bind('keypress',function(event){
		        if(event.keyCode == 13)
		        {
		          //校验工位是否存在
		          vaildWorkCellExist();
		        }
		    });

			// 默认为操作
			document.getElementById("operate").setAttribute("class",afterStyleStr);
			trackId = api.pageParam.trackId;
			disCodeState = api.pageParam.disCodeState;
		    op = api.pageParam.opId;
		    workCellCode = api.pageParam.workCellCode;
		    isNoFullUseHu = api.pageParam.isNoFullUseHu;
			//上表格赋值
		    var workOrderCode = api.pageParam.workOrderCode;
		    var workCellName = api.pageParam.workCellName;
		    mrl = api.pageParam.mrl;
		    var planQty = api.pageParam.planQty;

		    // $("#workCellName").html(workCellName == null ? '工位:' : "工位:" + workCellName);
			$("#mrl").html(mrl == null ? '产品:' : "产品:" + mrl);
			$("#planQty").html(planQty == null ? '计划数:' : "计划数:" + planQty);
      $("#workOrderCode").html(workOrderCode == null ? '工单:' : "工单:" + workOrderCode);
			$("#effectiveQty").html(effectiveQty == null ? '良品:0' : "良品:" + api.pageParam.effectiveQty);
			$("#uneffectiveQty").html(uneffectiveQty == null ? '不良品:0' : "不良品:" + api.pageParam.uneffectiveQty);
			$("#discardQty").html(discardQty == null ? '报废:0' : "报废:" + api.pageParam.discardQty);
			operateIndex = 1;
			//获取工位集合和执行工单记录集合
			// updateReportPageData(op,trackId);
      getTabList();

}

function onkeydownHuCode2() {
	if(event.keyCode==13){
		var text = document.getElementById("huCode2");
		saveMrl();
	}
}
//扫描
function toScanner(str) {
	 var moduleScanner = api.require('moduleScanner');
	 var params = {
			 top: 150, //扫描窗口的上边距
			 width: 250, //扫描窗口的宽
			 height: 250, //扫描窗口的高
			 useColor: false, //是否使用自己设定的颜色(startColor和endColor),
			 //如果不使用设定的颜色就使用默认的那张网格图
			 startColor: '#0F08C8FF', //渐变起始颜色
			 endColor: '#7F08C8FF', //渐变结束颜色
			 animTime: 2200, //扫描动画时间,单位为毫秒
	 };
	 moduleScanner.toScannerActivityForResult(params, function(ret, err) {
		 var SMequipCode = ret;
		//物料编码
		if (str == 'huCode2') {
			$("#huCode2").val(ret);
				saveMrl();
		}
	 });
}
function saveMrl(){
	//解析出条码中的 物料、批次 进行匹配明细
	//YDGYS-A,2810010-BQ01,2,2021031301,e7e26a1af372470987d7c5acb0040547,,,,,B-20210807-1918
	//供应商编码，物料编码，数量，批次号，不知道，，，，，箱号
	var codeBar=$("#huCode2").val();
	if(codeBar.lenght<3){
		api.toast({
				msg: '条码不匹配',
				duration: 3000
		});
		$("#huCode2").val("");
		return;
	}

	api.showProgress({
			title: '保存中...',
	});
	var t=setTimeout("test();",3000);

}
function test(){
	api.hideProgress();
	$("#huCode2").val("");
}

		function getTabList(){
			api.showProgress({
					title: '数据加载中...',
					text: '请稍等...',
					duration:15000,
			});
			var opCode = $("#workCellCode").val();
			var workOrderCode = $("#workOrderCode").val();

			var un = localStorage.getItem('un');
			var serverUrl = localStorage.getItem('serverUrl');
			var url = serverUrl + "/app/getPaDaqInfo";
			var params = new Object();
			params.url = url;
			params.method = 'post';
			params.dataType = 'json';
			var data = {
				values : {
					un:un,
					opCode : api.pageParam.opCode,
					workOrderCode : api.pageParam.workOrderCode,
					trackId: api.pageParam.trackId
				}
			};
			api.ajax({
					url: url,
					method: 'post',
					dataType: 'json',
					timeout: 300,
					returnAll: false,
					data: data
			}, function(ret, err) {
					if (ret) {
							var data = JSON.stringify(ret);
							var myobj = eval("(" + data + ")");
							//返回成功
							if (myobj.code == "0") {
									var trackRecordList = eval(myobj.list);
									var entity = eval(myobj.entity);//派工单信息
									$("#effectiveQty").html(entity.effectiveQty == null ? '良品:0' : "良品:" + entity.effectiveQty);
									$("#uneffectiveQty").html(entity.uneffectiveQty == null ? '不良品:0' : "不良品:" + entity.uneffectiveQty);
									$("#discardQty").html(entity.discardQty == null ? '报废:0' : "报废:" + entity.discardQty);

									var html = "";
									var seq = 1;
									for (var i = trackRecordList.length-1; i >= 0; i--) {
										if(i>=trackRecordList.length-trackRecordList.length) {
											var trackRecord = trackRecordList[i];
											var state = '';
											if (trackRecord.operateType == 0) {
												state = '开工';
											} else if (trackRecord.operateType == 1) {
												state = '暂停';
											} else if (trackRecord.operateType == 2) {
												state = '复工';
											} else if (trackRecord.operateType == 3) {
												state = '报工';
											} else if (trackRecord.operateType == 4) {
												state = '完工';
											}

											html += "<tr id='tr2' style=' display: table;width: 100%;table-layout: fixed;font-size: 13px;'>";
											html += "<td style='width:30px'>" + seq + "</td>"
											html += "<td style='width:70px'>" + state + "</td>"
											html += "<td style='width:50px'>" + trackRecord.effectiveQty + "</td>"
											html += "<td style='width:50px'>" + trackRecord.uneffectiveQty + "</td>"
											html += "<td style='width:50px'>" + trackRecord.discardQty + "</td>"
											html += "</tr>";
											seq++;
										}
									}
									$("#J_TbData").html(html);
									api.hideProgress();
									//失败
							} else if (myobj.code == "1") {
									//清空表格数据
									$api.html($api.byId("tbodyHtml"), "");
									api.toast({
											msg: myobj.message,
											duration: 3000
									});
							}
					}
			});
		}

		function setState(state){
			api.showProgress({
					title: '数据加载中...',
					text: '请稍等...',
					duration:15000,
			});
			var un = localStorage.getItem('un');
			var serverUrl = localStorage.getItem('serverUrl');
			var url = serverUrl + "/app/setPaDaqInfoState";
			var params = new Object();
			params.url = url;
			params.method = 'post';
			params.dataType = 'json';
			var data = {
				values : {
					un:un,
					opCode : api.pageParam.opCode,
					workOrderCode : api.pageParam.workOrderCode,
					trackId : api.pageParam.trackId,
					operateType:state
				}
			};
			api.ajax({
					url: url,
					method: 'post',
					dataType: 'json',
					timeout: 300,
					returnAll: false,
					data: data
			}, function(ret, err) {
					if (ret) {
							var data = JSON.stringify(ret);
							var myobj = eval("(" + data + ")");
							//返回成功
							if (myobj.code == "0") {
                  getTabList();
									api.hideProgress();
									//失败
							} else if (myobj.code == "1") {
									//清空表格数据
									$api.html($api.byId("tbodyHtml"), "");
									api.toast({
											msg: myobj.message,
											duration: 3000
									});
							}
					}
			});
		}
function goReportWork(){

				var values = {
					trackId : api.pageParam.trackId,
					name: api.winName

				}

				//标题来自动态传递
				// api.openFrame({
				// 	name : 'workCell-report_operate_submit',
				// 	url : 'workCell-report_operate_submit.html',
				// 	pageParam : values,
				// 	bounces : false,
				// });
				api.openWin({
					name : 'operation-report_operate_submit',
					url : 'operation-report_operate_submit.html',
					pageParam : values,
					bounces : false,
				});
}
//返回按钮
function closeWin() {
		api.closeWin({});
		api.execScript({
				name: api.pageParam.name,
				script: 'queryWorkTaskOrder()'
		});
}


	</script>
</html>
